<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增专业')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-major-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">专业名称：</label>
                <div class="col-sm-8">
                    <input name="majorName" id="majorName" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">所属部门：</label>
                <div class="col-sm-8">
                        <select name="deptId" th:with="dept=${@deptService.selectAllDept(null)}">
                            <option value="">所有</option>
                            <option th:each="d : ${dept}" th:text="${d.deptName}" th:value="${d.deptId}">
                            </option>
                        </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/major";

        $("#form-major-add").validate({
            onkeyup: false,
            rules: {
                majorName: {
                    remote: {
                        url: prefix + "/checkMajorNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "majorName": function () {
                                return $.common.trim($("#majorName").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }
            },
            messages: {
                "majorName": {
                    remote: "专业名称已存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-major-add').serialize());
            }
        }
    </script>
</body>
</html>